package com.xin.data.simbapesa.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.xin.data.simbapesa.base.BaseDialog;
import com.xin.data.simbapesa.databinding.SimbaTipsDialogBinding;
import com.xin.data.simbapesa.utils.ViewUtils;


public class TipsDialog extends BaseDialog<SimbaTipsDialogBinding> {
    public TipsDialog(@NonNull Context context) {
        super(context);
    }

    public TipsDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected TipsDialog(@NonNull Context context, boolean cancelable, @Nullable DialogInterface.OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected SimbaTipsDialogBinding initViewBinding(LayoutInflater inflater) {
        return SimbaTipsDialogBinding.inflate(inflater);
    }

    @Override
    protected void initView() {
        binding.tvOk.setSelected(true);
        binding.tvCancel.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            dismiss();
            if (onBtnClickListener != null) {
                onBtnClickListener.btnOnClickCancel();
            }
        });
        binding.tvClose.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            dismiss();
            if (onBtnClickListener != null) {
                onBtnClickListener.btnOnClickCancel();
            }
        });
        binding.tvOk.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            dismiss();
            if (onBtnClickListener != null) {
                onBtnClickListener.btnOnClickOk();
            }
        });

    }


    public void setOkClickable(boolean isTrue) {
        binding.tvOk.setClickable(isTrue);
        binding.tvOk.setSelected(isTrue);
    }


    public void setTitle(String title) {
        binding.tvTitle.setText(title);
    }

    public void setCancelTxt(String txt) {
        binding.tvCancel.setText(txt);
    }

    public void setOkTxt(String txt) {
        binding.tvOk.setText(txt);
    }

    public void setContentTxt(String txt) {
        if (!TextUtils.isEmpty(txt)) {
            binding.tvContent.setText(Html.fromHtml(txt));
        }
    }

    public void hideCancel(boolean isHide) {
        if (isHide) {
            binding.tvCancel.setVisibility(View.GONE);
        } else {
            binding.tvCancel.setVisibility(View.VISIBLE);
        }
    }

}